<template>
  <el-tabs v-model="activeName" type="card">
    <el-tab-pane v-for="item in data" :key="item.name" :lazy="true" :label="item.name" :name="item.name">
      <Java :value="item.content" :height="height" />
    </el-tab-pane>
  </el-tabs>
</template>

<script>
import Java from '@/components/JavaEdit/index'
import api from '@/api/service'

export default {
  name: 'Preview',
  components: { Java },
  data() {
    return {
      data: null,
      height: '',
      activeName: 'Entity'
    }
  },
  created() {
    this.height = document.documentElement.clientHeight - 130 + 'px'
    if (!this.$route.query.id) {
      this.$message.error('参数错误!')
      this.$router.go(-1)
    }

    api.newRequest('table', 'preview', { id: this.$route.query.id }).then(res => {
      if (res.code === 200) {
        this.data = res.data
      } else {
        this.$message.error(res.msg)
      }
    }).catch(() => {
      this.$router.go(-1)
    })
  }
}
</script>
